import { TMPLID } from './constant.js'

/**
 * @description: 订阅消息
 * @author: majun
 */
export async function messageSubscription() {
  try {
    const res = await wx.requestSubscribeMessage({
      tmplIds: [TMPLID], // 替换为你的订阅消息模板 ID
      scene: '1001' // 替换为你的订阅消息场景值
    })
    // const obj = await wx.getSetting()
    // console.log('obj:', obj)
    console.log('订阅消息成功:', res)
    console.log('订阅消息成功:', res[TMPLID])
    if (res[TMPLID] === 'accept') {
      return res
    } else {
      throw new Error('用户取消订阅')
    }
  } catch (error) {
    console.log('订阅消息失败:', error)
    throw error
  }
}
